Constants

MAX_EXP_LEVEL

MAX_EXP_LEVEL = 2

DATE_FORMAT

DATE_FORMAT = 'Y-m-d H:i:s.u'

DATE_FORMAT_REGEX

DATE_FORMAT_REGEX = '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{1,6}'

Properties

$type

$type

$userid

$userid

$prefix

$prefix

$ttl

$ttl

$packed

$packed

$indexed

$indexed

$index

$index

$index_update

$index_update

$cache

$cache

$updates

$updates

$exp_records

$exp_records

$refresh_time

$refresh_time

$debug

$debug

$max_packet

$max_packet

$db

$db : \rcube_db

Instance of database handler

Type

rcube_db

$table

$table : string

(Escaped) Cache table name (cache or cache_shared)

Type

string

Methods

factory()

factory(string  $type, int  $userid, string  $prefix = '', string  $ttl, bool  $packed = true, bool  $indexed = false) : mixed

Object factory

Parameters

string $type

Engine type ('db', 'memcache', 'apc', 'redis')

int $userid

User identifier

string $prefix

Key name prefix

string $ttl

Expiration time of memcache/apc items

bool $packed

Enables/disabled data serialization. It's possible to disable data serialization if you're sure stored data will be always a safe string

bool $indexed

Use indexed cache. Indexed cache is more appropriate for storing big data with possibility to remove it by a key prefix. Non-indexed cache does not remove data, but flags it for expiration, also stores it in memory until close() method is called.

Returns

mixed —

__construct()

__construct(mixed  $userid, mixed  $prefix = '', mixed  $ttl, mixed  $packed = true, mixed  $indexed = false) : mixed

Object constructor.

Parameters

mixed $userid

User identifier

mixed $prefix

Key name prefix

mixed $ttl

Expiration time of memcache/apc items

mixed $packed

Enables/disabled data serialization. It's possible to disable data serialization if you're sure stored data will be always a safe string

mixed $indexed

Use indexed cache. Indexed cache is more appropriate for storing big data with possibility to remove it by key prefix. Non-indexed cache does not remove data, but flags it for expiration, also stores it in memory until close() method is called.

Returns

mixed —

get()

get(string  $key) : mixed

Returns cached value.

Parameters

string $key

Cache key name

Returns

mixed —

Cached value

set()

set(string  $key, mixed  $data) : bool

Sets (add/update) value in cache.

Parameters

string $key

Cache key name

mixed $data

Cache data

Returns

bool —

True on success, False on failure

read()

read(mixed  $key) : mixed

Parameters

mixed $key

Returns

mixed —

write()

write(mixed  $key, mixed  $data) : mixed

Parameters

mixed $key
mixed $data

Returns

mixed —

remove()

remove(string  $key = null, bool  $prefix_mode = false) : mixed

Clears the cache.

Parameters

string $key

Cache key name or pattern

bool $prefix_mode

Enable it to clear all keys starting with prefix specified in $key

Returns

mixed —

expunge()

expunge() : mixed

Remove cache records older than ttl

Returns

mixed —

gc()

gc() : mixed

Remove expired records of all caches

Returns

mixed —

close()

close() : mixed

Writes the cache back to the DB.

Returns

mixed —

key_name()

key_name(string  $prefix, array  $params = []) : string

A helper to build cache key for specified parameters.

Parameters

string $prefix

Key prefix (Max. length 64 characters)

array $params

Additional parameters

Returns

string —

Key name

read_record()

read_record(string  $key) : mixed

Reads cache entry.

Parameters

string $key

Cache key name

Returns

mixed —

Cached value

write_record()

write_record(string  $key, mixed  $data) : bool

Writes single cache record into DB.

Parameters

string $key

Cache key name

mixed $data

Serialized cache data

Returns

bool —

True on success, False on failure

remove_record()

remove_record(string  $key = null, bool  $prefix_mode = false) : mixed

Deletes the cache record(s).

Parameters

string $key

Cache key name or pattern

bool $prefix_mode

Enable it to clear all keys starting with prefix specified in $key

Returns

mixed —

remove_record_indexed()

remove_record_indexed(mixed  $key = null, mixed  $prefix_mode = false) : mixed

Parameters

mixed $key
mixed $prefix_mode

Returns

mixed —

write_index()

write_index(mixed  $force = null) : mixed

Writes the index entry as well as updated entries into memcache/apc/redis DB.

Parameters

mixed $force

Returns

mixed —

load_index()

load_index() : mixed

Gets the index entry from memcache/apc/redis DB.

Returns

mixed —

store_record()

store_record(string  $key, mixed  $data, \DateTime  $ts = null) : mixed

Writes single cache record into DB.

Parameters

string $key

Cache key name

mixed $data

Serialized cache data

\DateTime $ts

Timestamp

Returns

mixed —

get_item()

get_item(string  $key) : mixed

Fetches cache entry.

Parameters

string $key

Cache internal key name

Returns

mixed —

Cached value

add_item()

add_item(string  $key, mixed  $data) : mixed

Adds entry into memcache/apc/redis DB.

Parameters

string $key

Cache internal key name

mixed $data

Serialized cache data

Returns

mixed —

delete_item()

delete_item(string  $key) : mixed

Deletes entry from memcache/apc/redis DB.

Parameters

string $key

Cache internal key name

Returns

mixed —

get_exp_timestamp()

get_exp_timestamp(mixed  $key) : mixed

Get EXP:<key> record value from cache

Parameters

mixed $key

Returns

mixed —

ikey()

ikey() : string

Creates per-user index cache key name (for memcache, apc, redis)

Returns

string —

Cache key

ckey()

ckey(string  $key) : string

Creates per-user cache key name (for memcache, apc, redis)

Parameters

string $key

Cache key name

Returns

string —

Cache key

ekey()

ekey(string  $key, mixed  $prefix = null) : string

Creates per-user cache key name for expiration time entry

Parameters

string $key

Cache key name

mixed $prefix

Returns

string —

Cache key

serialize()

serialize(mixed  $data) : mixed

Serializes data for storing

Parameters

mixed $data

Returns

mixed —

unserialize()

unserialize(mixed  $data) : mixed

Unserializes serialized data

Parameters

mixed $data

Returns

mixed —

max_packet_size()

max_packet_size() : mixed

Determine the maximum size for cache data to be written

Returns

mixed —

debug()

debug(mixed  $type, mixed  $key, mixed  $data = null, mixed  $result = null) : mixed

Write memcache/apc/redis debug info to the log

Parameters

mixed $type
mixed $key
mixed $data
mixed $result

Returns

mixed —